package com.ruoyi.system.service.impl;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.PressureReliefAndBackstopEquipment;
import com.ruoyi.system.mapper.PressureReliefAndBackstopEquipmentMapper;
import com.ruoyi.system.service.PressureReliefAndBackstopEquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 泄压和止逆设备(PressureReliefAndBackstopEquipment)表服务实现类
 *
 * @author makejava
 * @since 2022-11-15 16:50:57
 */
@Service
public class PressureReliefAndBackstopEquipmentServiceImpl implements PressureReliefAndBackstopEquipmentService {
    @Autowired
    private PressureReliefAndBackstopEquipmentMapper pressureReliefAndBackstopEquipmentDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PressureReliefAndBackstopEquipment queryById(Integer id) {
        return this.pressureReliefAndBackstopEquipmentDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param pressureReliefAndBackstopEquipment 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<PressureReliefAndBackstopEquipment> queryByPage(PressureReliefAndBackstopEquipment pressureReliefAndBackstopEquipment, PageRequest pageRequest) {
        long total = this.pressureReliefAndBackstopEquipmentDao.count(pressureReliefAndBackstopEquipment);
        return new PageImpl<>(this.pressureReliefAndBackstopEquipmentDao.queryAllByLimit(pressureReliefAndBackstopEquipment, pageRequest), pageRequest, total);
    }

    @Override
    public List<PressureReliefAndBackstopEquipment> selectList(PressureReliefAndBackstopEquipment pressureReliefAndBackstopEquipment) {
        return pressureReliefAndBackstopEquipmentDao.queryAll(pressureReliefAndBackstopEquipment);
    }

    /**
     * 新增数据
     *
     * @param pressureReliefAndBackstopEquipment 实例对象
     * @return 实例对象
     */
    @Override
    public PressureReliefAndBackstopEquipment insert(PressureReliefAndBackstopEquipment pressureReliefAndBackstopEquipment) {
        this.pressureReliefAndBackstopEquipmentDao.insert(pressureReliefAndBackstopEquipment);
        return pressureReliefAndBackstopEquipment;
    }

    /**
     * 修改数据
     *
     * @param pressureReliefAndBackstopEquipment 实例对象
     * @return 实例对象
     */
    @Override
    public PressureReliefAndBackstopEquipment update(PressureReliefAndBackstopEquipment pressureReliefAndBackstopEquipment) {
        this.pressureReliefAndBackstopEquipmentDao.update(pressureReliefAndBackstopEquipment);
        return this.queryById(pressureReliefAndBackstopEquipment.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.pressureReliefAndBackstopEquipmentDao.deleteById(id) > 0;
    }

    @Override
    public String importExcel(List<PressureReliefAndBackstopEquipment> pressureReliefAndBackstopEquipments, Boolean isUpdateSupport, String operName) {
        if (StringUtils.isNull(pressureReliefAndBackstopEquipments) || pressureReliefAndBackstopEquipments.size() == 0) {
            throw new ServiceException("导入用户数据不能为空！");
        }
        pressureReliefAndBackstopEquipmentDao.insertBatch(pressureReliefAndBackstopEquipments);
        return "成功";
    }
}
